package edu.imac.angryfood.game;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import edu.imac.angryfood.states.GameState;
import edu.imac.angryfood.states.MainMenuState;
import edu.imac.angryfood.states.SelectPlayerState;
import edu.imac.angryfood.states.SelectLevelState;
import edu.imac.angryfood.states.CreditState;
import edu.imac.angryfood.utils.Account;
import edu.imac.angryfood.utils.PlayersHost;

/**
 * Main application : the games' screen are handled here + Main ()
 */

public class Angryfood extends StateBasedGame {
	
	/** xml's path of the current level */
	public String currentLevel = ""; 
	/** Account of the player who is playing */
	private Account current_Player = new Account("toto", "toto", "", 1);
	/** Boolean used to reinitialize the states, it restarts the init fonction */
	public Boolean load_player = false;
	/** Boolean used to reinitialize the level, it restarts the init fonction */
	public Boolean load_level = false;
	

	public Account getCurrentPlayer() {
		return current_Player;
	}
	
   public void setCurrentPlayer(Account cP) {
		this.current_Player.setName(cP.getName());
		this.current_Player.setLast_level(cP.getLast_level());
		this.current_Player.setMax_score(cP.getMax_score());
		this.current_Player.setPassword(cP.getPassword());
	}
   

	/**
	 * Constructor of the game
	 * @param name : The name of the Game
	 */

	public Angryfood(String name) {
		super(name);
	}

	/**
	 * Create the list of the differents states of the game
	 * @param container : it represents the container of the game
	 */
	public void initStatesList(GameContainer container) throws SlickException {

		addState(new MainMenuState(this, 0)); 
	    addState(new CreditState(this, 2)); 
		addState(new SelectPlayerState(this, 1));
		addState(new SelectLevelState(this, 3));
		addState(new GameState(this, 4, 1, 1));
		
	}


	/**
	 * Main
	 * @param argv : arguments
	 */
	public static void main(String[] argv) {
		int minLogicUpdate = 10;
		
		try {
			AppGameContainer container = new AppGameContainer(new Angryfood( "Angryfood !"));
			
			/**False : no full screen**/
			container.setDisplayMode(800, 600, false);
			container.setShowFPS(true);
			//container.setTargetFrameRate(60);
			container.setVSync(true);
			container.setMinimumLogicUpdateInterval(minLogicUpdate);
			
			/** Start players controls **/
			/** Creation of the singleton server **/
			PlayersHost.getInstance();
			
			/** Chargement of the file in a vector **/
			PlayersHost.getInstance().load();
			System.out.println(PlayersHost.getInstance().toStringComptes());
			
			container.start();
		} catch (SlickException e) {
			e.printStackTrace();
		}
	}
}
